package impl.jdkimpl;

import common.UserService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by chenjun on 2017/11/21.
 */
public class ServiceHandler implements InvocationHandler {


    private UserService userService;

    public  ServiceHandler(UserService userService){
        this.userService = userService;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = null;

        before();
        result = method.invoke(this.userService,args);
        after();

        return  result;
    }

    public  void before(){
        System.out.println("---before----");

    }

    public  void after(){
        System.out.println("---after----");
    }
}
